file_object = open('thefile.txt')
try:
    all_the_text = file_object.read()
finally:
    file_object.close()

f = open("foo.txt")  # 返回一个文件对象
line = f.readline()  # 调用文件的 readline()方法

while line:
    print(line),  # 后面跟 ',' 将忽略换行符
    line = f.readline()
f.close()

# for line in open("foo.txt"):

f = open("c:\\1.txt", "r")
lines = f.readlines()  # 读取全部内容
for line in lines:
    print(line)

############################

output = open('data', 'w+')

file_object.write(all_the_text)

file_object.close()

# 写入多行

# file_object.writelines(list_of_text_strings)
